﻿////Thể hiện thông báo khi có lỗi không kết nối với máy chủ
var onFailure = function () {
    alert('Không thể kết nối tới máy chủ, hoặc đã có lỗi xảy ra, vui lòng thử lại.');
    Ext.Msg.hide();
    parent.Ext.Msg.hide();
};

var hideWait = function () {
    Ext.Msg.hide();
    parent.Ext.Msg.hide();
}

///Thể hiện hộp thoại chờ
var showWait = function () {
    parent.Ext.Msg.wait('Tải form ...', 'Loading');
}

///Xử lý xâu
String.prototype.replaceAll = function (
            strTarget, // The substring you want to replace
            strSubString // The string you want to replace in.
            ) {
    var strText = this;
    var intIndexOfMatch = strText.indexOf(strTarget);

    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1) {
        // Relace out the current instance.
        strText = strText.replace(strTarget, strSubString)
        // Get the index of any next matching substring.
        intIndexOfMatch = strText.indexOf(strTarget);
    }

    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return (strText);
}

///Lấy Id của TabPanel
var getTabPanelID = function () {
    var id = window.frameElement.id;
    return id.replace("_IFrame", "");
}

function closeWindow() {
    wId = getTabPanelID();
    parent.Ext.WindowMgr.get(wId).close();
}

var renderImageUtil = function (value, w) {
    return "<img src='" + value + "?w=" + w + "' />";
}



function BrowseServer() {
    // You can use the "CKFinder" class to render CKFinder in a page:
    var finder = new CKFinder();
    finder.basePath = '/plugins/ckfinder/'; // The path for the installation of CKFinder (default = "/ckfinder/").
    finder.selectActionFunction = SetFileField;
    finder.popup();
}


//FCKEditor Js API
var getFckText = function () {
    return CKEDITOR.instances.fckHtmlEditor.getData();
}


function loadEditor() {
    var oFCKeditor = CKEDITOR.replace('fckHtmlEditor', {
        customConfig: '../../../plugins/ckeditor/config.js',
        filebrowserBrowseUrl: '../../../plugins/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl: '../../../plugins/ckfinder/ckfinder.html',
        filebrowserFlashBrowseUrl: '../../../plugins/ckfinder/ckfinder.html?type=Flash',
        filebrowserUploadUrl: '../../../plugins/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl: '../../../plugins/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl: '../../../plugins/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash'

    });

    oFCKeditor.BasePath = '../../../plugins/ckeditor/';
    oFCKeditor.Width = '680px';
    oFCKeditor.Skin = 'v2';
    oFCKeditor.Height = '250px';
}

function setHtml(html) {
    return CKEDITOR.instances.fckHtmlEditor.setData(html);
}
